package com.luych.toolbox.common.feign.intf.base.service;

import com.luych.toolbox.common.constant.PageConstant;
import com.luych.toolbox.common.enums.TaskStatus;
import com.luych.toolbox.common.feign.FeignInterface;
import com.luych.toolbox.common.feign.param.base.service.TaskParam;
import com.luych.toolbox.common.feign.view.base.service.TaskView;
import com.luych.toolbox.common.page.CommonPageResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

@FeignClient(contextId = "base-service-task", name = "base-service", path = "/task", decode404 = true)
public interface TaskFeign extends FeignInterface<TaskView, TaskParam> {


    @ApiOperation("按关键字查询")
    @GetMapping("/search/keyword")
    TaskPageResult pageByKeyword(
            @ApiParam(value = "每页容量") @RequestHeader(name = "pageSize", required = false, defaultValue = PageConstant.DEFAULT_PAGE_SIZE_STR) long pageSize,
            @ApiParam(value = "查询页码") @RequestHeader(name = "pageNumber", required = false, defaultValue = PageConstant.DEFAULT_PAGE_NUMBER_STR) long pageNumber,
            @ApiParam(value = "排序字段") @RequestHeader(name = "sort", required = false, defaultValue = PageConstant.DEFAULT_PAGE_SORT) String sort,
            @ApiParam(value = "正序/倒序，取值ASC/DESC") @RequestHeader(name = "order", required = false, defaultValue = PageConstant.DEFAULT_PAGE_ORDER) String order,
            @ApiParam(value = "查询关键字") @RequestParam(name = "keyword", required = false) String keyword,
            @ApiParam(value = "状态") @RequestParam(name = "status", required = false) TaskStatus status
    );

    @ApiOperation("开始")
    @PostMapping(path = "/{id}/start")
    void start(@ApiParam(value = "ID") @PathVariable("id") String id);

    @ApiOperation("完成")
    @PostMapping(path = "/{id}/complete/{status}")
    void complete(@ApiParam(value = "ID") @PathVariable("id") String id,
                  @ApiParam(value = "状态") @PathVariable("status") TaskStatus status,
                  @ApiParam(value = "输出") @RequestBody String stdout
    );

    public static class TaskPageResult extends CommonPageResult<TaskView> {
        private long pending;
        private long running;
        private long success;
        private long error;

        public long getPending() {
            return pending;
        }

        public void setPending(long pending) {
            this.pending = pending;
        }

        public long getRunning() {
            return running;
        }

        public void setRunning(long running) {
            this.running = running;
        }

        public long getSuccess() {
            return success;
        }

        public void setSuccess(long success) {
            this.success = success;
        }

        public long getError() {
            return error;
        }

        public void setError(long error) {
            this.error = error;
        }
    }
}
